package com.fz.study.project.controller;


import com.fz.study.project.entity.AdminUser;
import com.fz.study.project.entity.Result;
import com.fz.study.project.service.IAdminUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-02-05
 */
@Tag(name = "系统管理员信息")
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/adminuser")
public class AdminUserController {

    private final IAdminUserService adminUserService;
    @Operation(summary = "显示所有信息")
    @GetMapping("/list")
    public Result ListAdminInfo(){
        return Result.success(adminUserService.list());
    }

    @Operation(summary = "添加")
    @PutMapping("/save")
    public Result save(@RequestBody AdminUser user){
        adminUserService.saveByName(user);
        return Result.success();
    }

    @Operation(summary = "修改")
    @PutMapping("update")
    public Result updateById(@RequestBody AdminUser user){
        adminUserService.updateByUser(user);
        return Result.success("修改成功");
    }

    @Operation(summary = "删除")
    @DeleteMapping("{ids}")
    public Result deleteByIds(@PathVariable List<Integer> ids){
        adminUserService.deleteByIds(ids);
        return Result.success("删除成功!");
    }

}
